<?php
	require '../include/library.inc.php';
	require '../include/admin_login.inc.php';
	require '../include/paging.inc.php';
	
	
	$lang = 1;
	$sql = "SELECT
				c.page_id,
				c.order_number,
				c.published,
				
				d.title
				
			FROM
				pages AS c,
				page_description AS d
			WHERE
			
				c.page_id = d.page_id
				
				AND
				
				d.lang_id = '".$lang."'
			  ";
			  
	if ($page_id) {
		/*$sql .=	'
				,
				product_categories AS pc
			WHERE
				p.product_id = pc.product_id
			AND
				category_id = '.$category_id.'
		';*/
	}
	
	
	if (!isset($_GET['sort'])) $_GET['sort'] = 1;
	if (!isset($_GET['sortBy'])) $_GET['sortBy'] = 2;
	
	$paging = new Paging($sql, $_GET['sortBy'], $_GET['sort'], array(2=>"Подредба"), 30);
	$result = $paging->query();
		
		head_admin("Страници");
	?>
			
				<?php if ($_SESSION['message']) { ?>
				<div class="message green">
					<?=$_SESSION['message']?>
				</div>
				<?php unset($_SESSION['message']); } ?>
			
			
				<div class="topbuttons">
					<a href="page_new.php">Добави нова страница</a>
					
				</div>
				<h3>Страници (<?=$paging->count()?>)</h3>
				
				<table id="listing" width="100%" cellpadding="0" cellspacing="0">
					<thead>
                        <tr>
                            <td>Име</td>
                            <td>Публикуван</td>
                            <td>Подредба</td>
                            <td>Действия</td>
                        </tr>
                    </thead>
				<tbody>
				<?php
				  
				  
				  $i=1;
				  while ($row = mysql_fetch_object($result)) {				  
				?>
						<tr class="<?=(($i%2)?"none":"zebra")?>">
							<td>
                            	<a href="page_edit.php?page_id=<?=$row->page_id?>" title="Редактирай"><?=sth($row->title)?></a></td>
							
							<td class="switch">
								<?php if ($row->published) { ?>
								 <a href="page_publish.php?page_id=<?=$row->page_id?>&publish=0" class="turn_on" name="turn_on" title="Спри"></a>
								<?php } else { ?> 
								 <a href="page_publish.php?page_id=<?=$row->page_id?>&publish=1" class="turn_off" name="turn_off" title="Публикувай"></a>
								<?php } ?>	
							</td>
							
							<td class="sort">
								<?php if ($i != 1) { ?>
								<a name="Up" class="sorting_up" title="Нагоре" href="page_direction.php?page_id=<?=$row->page_id?>&direction=1"></a>
								<?php } ?>							
								<?php if ($i != ($paging->count())) { ?>
								<a name="Down" class="sorting_down" title="Надолу" href="page_direction.php?page_id=<?=$row->page_id?>&direction=-1"></a>
								<?php } ?>
								&nbsp;<!--ie6 bug-->
							</td>
							
							<td class="icons">
								<a name="Top" class="sorting_top" title="Top" href="page_direction.php?page_id=<?=$row->page_id?>&top=1">Top</a>
								
								<a href="page_edit.php?page_id=<?=$row->page_id?>" class="edit" title="Редактирай">Редактирай</a> 
								<a onClick="if (window.confirm('Сигурен ли си, че искаш да изтриеш <?=sth($row->title)?>?')) { document.location='page_del.php?page_id=<?=$row->page_id?>'; return false; }" class="delete" title="Изтрий">Изтрий</a>
							</td>
							
						</tr>
			 <?php
				  $i++;    
				} 
			 ?>				  
				</tbody>
			</table>
			
			<div class="pagingwrap"><div class="paging">
				<?=$paging->display()?>
			</div></div>
            
<?php
	foot_admin(); 
?>